﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SalaryTemplateList.aspx.cs" Inherits="KPI_SYSTEM.SalaryPage.SalaryTemplateList" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
    <style>
        
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <f:PageManager ID="PageManager1" runat="server" />

        <f:Form ID="Form2" IsFluid="true" CssClass="blockpanel" BodyPadding="5 5 0 5" LabelAlign="Left" ShowHeader="false"
            Title="查询" runat="server">
            <Rows>
                <f:FormRow ColumnWidths="15% 15% 8% 8% 8% 8%">
                    <Items>
                        <f:TextBox runat="server" ID="tbxNameSerach" Label="名称"></f:TextBox>
                        <f:TriggerBox runat="server" ID="tbxMonthSearch" Label="月份" TriggerIcon="Date"></f:TriggerBox>
                        <f:Button ID="btnSearch" Text="搜索" Icon="Magnifier" runat="server" OnClick="btnSearch_Click"></f:Button>
                    </Items>
                    <Items>
                    </Items>
                </f:FormRow>
            </Rows>
        </f:Form>

        <f:Grid ID="Grid1" IsFluid="true" CssClass="blockpanel" ShowBorder="true" ShowHeader="true" EnableCollapse="false"
            runat="server" DataKeyNames="REC_ID" DataIDField="REC_ID" AllowCellEditing="false" PageSize="15" AllowPaging="true"
            Title="工资模板信息" OnRowCommand="Grid1_RowCommand" OnPreRowDataBound="Grid1_PreRowDataBound" EnableColumnLines="true">
            <Toolbars>
                <f:Toolbar ID="Toolbar2" Position="Top" runat="server">
                    <Items>
                        <f:Button ID="btnNew" Text="新增" Icon="Add" EnablePostBack="false" runat="server">
                            <Listeners>
                                <f:Listener Event="click" Handler="onNewButtonClick" />
                            </Listeners>
                        </f:Button>
                        <f:Button ID="btnPreviewTemplate" Text="预览模板"  EnableAjax="false"  runat="server" OnClick="btnPreviewTemplate_Click"></f:Button>
                        
                        <f:Button ID="Button1" Text="上传明细" runat="server" EnablePostBack="false">
                            <Listeners>
                                <f:Listener Event="click" Handler="onUploadExcel" />
                            </Listeners>
                        </f:Button>
                        <f:Button ID="btnLookDetail" Text="查看明细" Icon="TextListBullets" EnableAjax="false" runat="server" OnClick="btnLookDetail_Click">
                        </f:Button>
                        <f:Button ID="btnSendMessage" Text="发送工资通知" Icon="CommentsAdd" 
                            runat="server" OnClick="btnSendMessage_Click">
                        </f:Button>
                    </Items>
                </f:Toolbar>
            </Toolbars>
            <Columns>
                <f:TemplateField Width="60px">
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
                    </ItemTemplate>
                </f:TemplateField>
                <f:RenderField Width="150px" ColumnID="TEMPLATE_NAME" DataField="TEMPLATE_NAME"
                    HeaderText="模板名称">
                </f:RenderField>
                <f:RenderField Width="150px" ColumnID="TEMPLATE_DATA" DataField="TEMPLATE_DATA"
                    HeaderText="模板月份">
                </f:RenderField>
                <f:RenderField Width="150px" ColumnID="TEMPLATE_STATUS_NAME" DataField="TEMPLATE_STATUS_NAME"
                    HeaderText="明细状态">
                </f:RenderField>
                <f:RenderField Width="200px" ColumnID="TEMPLATE_REMARK" DataField="TEMPLATE_REMARK"
                    HeaderText="发送信息备注">
                </f:RenderField>
                <f:RenderField Hidden="true" ColumnID="TEMPLATE_STATUS" DataField="TEMPLATE_STATUS"
                    HeaderText="是否上传ID">
                </f:RenderField>
                <f:RenderField Hidden="true" ColumnID="TEMPLATE_ITEM" DataField="TEMPLATE_ITEM"
                    HeaderText="工资项ID">
                </f:RenderField>
                <f:RenderField Hidden="true" ColumnID="TEMPLATE_TOTAL" DataField="TEMPLATE_TOTAL"
                    HeaderText="合计项ID">
                </f:RenderField>
                <f:LinkButtonField ColumnID="Edit" Width="50px" EnablePostBack="false"
                    Icon="Pencil" />
                <f:LinkButtonField Width="50px" ConfirmText="删除选中行？" ConfirmTarget="Top"
                    CommandName="Delete" Icon="Delete" />
            </Columns>
        </f:Grid>

        <f:Window ID="Window1" Title="编辑信息" Hidden="true" EnableIFrame="false"
            EnableMaximize="true" Target="Self" EnableResize="true" runat="server"
            IsModal="true" Width="950px">
            <Items>
                <f:SimpleForm ID="SimpleForm1" runat="server" ShowBorder="false" ShowHeader="false" BodyPadding="10px">
                    <Items>
                        <f:Panel ID="Panel1" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:HiddenField ID="hfFormID" runat="server"></f:HiddenField>
                                <f:TextBox ID="tbxFormTEMPLATE_NAME" Label="模板名称" Width="310px" runat="server" Required="true" ShowRedStar="true"></f:TextBox>
                                <f:TriggerBox ID="tbxFormTEMPLATE_DATA" Label="工资月份" Width="310px" MarginLeft="20px" TriggerIcon="Date" runat="server" Required="true" ShowRedStar="true"></f:TriggerBox>
                                <f:TextBox ID="tbxFormTEMPLATE_REMARK" Label="发送信息备注" LabelWidth="150px" Width="310px" MarginLeft="20px" runat="server"></f:TextBox>
                            </Items>
                        </f:Panel>
                    </Items>
                    <Items>
                        <f:Panel ID="Panel2" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:CheckBoxList ID="chlFormSALARY_ITEMS" Label="发款项" ColumnNumber="3" ColumnVertical="true" runat="server">
                                </f:CheckBoxList>
                            </Items>
                        </f:Panel>
                    </Items>
                    <Items>
                        <f:Panel ID="Panel6" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:CheckBoxList ID="chlFormDEDUCT_ITEMS" Label="扣款项" ColumnNumber="3" ColumnVertical="true" runat="server">
                                </f:CheckBoxList>
                            </Items>
                        </f:Panel>
                    </Items>
                     <Items>
                        <f:Panel ID="Panel5" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:CheckBoxList ID="chlFormTOTAL_SALARY_ITEMS" Label="合计发款项" ColumnNumber="3" ColumnVertical="true" runat="server">
                                </f:CheckBoxList>
                            </Items>
                        </f:Panel>
                    </Items>
                       <Items>
                        <f:Panel ID="Panel7" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:CheckBoxList ID="chlFormTOTAL_DEDUCT_ITEMS" Label="合计扣款项" ColumnNumber="3" ColumnVertical="true" runat="server">
                                </f:CheckBoxList>
                            </Items>
                        </f:Panel>
                    </Items>
                    <Toolbars>
                        <f:Toolbar ID="Toolbar1" Position="Bottom" ToolbarAlign="Right" runat="server">
                            <Items>
                                <f:Button ID="btnSave"
                                    Icon="SystemSave" runat="server" Text="保存数据" ValidateForms="SimpleForm1" OnClick="btnSave_Click">
                                </f:Button>
                            </Items>
                        </f:Toolbar>
                    </Toolbars>
                </f:SimpleForm>
            </Items>
        </f:Window>
        <f:Window ID="Window2" Title="上传工资明细" Hidden="true" EnableIFrame="false"
            EnableMaximize="true" Target="Self" EnableResize="true" runat="server"
            IsModal="true" Width="400px">
            <Items>
                <f:SimpleForm ID="SimpleForm2" runat="server" ShowBorder="false" ShowHeader="false" BodyPadding="10px">
                    <Items>
                        <f:Panel ID="Panel3" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:TextBox ID="tbxFormUploadMessage" Label="工资条信息" runat="server" Readonly="true"></f:TextBox>
                            </Items>
                        </f:Panel>
                    </Items>
                    <Items>
                        <f:Panel ID="Panel4" ShowHeader="false" CssClass="" ShowBorder="false" Layout="Column" runat="server">
                            <Items>
                                <f:FileUpload runat="server" ID="fileUploadExcel" EmptyText="请上传EXCEL" Label="上传EXCEL" ButtonIcon="Add"
                                    ShowRedStar="true" Required="true">
                                </f:FileUpload>
                            </Items>
                        </f:Panel>
                    </Items>
                    <Toolbars>
                        <f:Toolbar ID="Toolbar3" Position="Bottom" ToolbarAlign="Right" runat="server">
                            <Items>
                                <f:Button ID="btnSaveDetail"
                                    Icon="SystemSave" runat="server" Text="保存"  ValidateForms="SimpleForm2" OnClick="btnSaveDetail_Click">
                                </f:Button>
                            </Items>
                        </f:Toolbar>
                    </Toolbars>
                </f:SimpleForm>
            </Items>
        </f:Window>
        <f:Window ID="Window3" Title="工资模板信息" Hidden="true" EnableIFrame="false"
            EnableMaximize="true" Target="Self" EnableResize="true" runat="server"
            IsModal="true" Width="900px" >
            <Items>

                <f:SimpleForm ID="SimpleForm3" runat="server" ShowBorder="false" ShowHeader="false" BodyPadding="10px">
                    <Items>
                        <f:Grid ID="GridSalaryDetail" IsFluid="true" CssClass="blockpanel" EnableColumnLines="true"
                            DataKeyNames="REC_ID" DataIDField="REC_ID" ShowBorder="true" ShowHeader="false" runat="server">
                            <Columns>
                                <f:RenderField Width="100px" ColumnID="USER_NAME" DataField="USER_NAME"
                                    HeaderText="姓名">
                                </f:RenderField>
                                <f:RenderField Width="100px" ColumnID="USER_CODE" DataField="USER_CODE"
                                    HeaderText="工号">
                                </f:RenderField>
                            </Columns>
                        </f:Grid>

                       
                    </Items>
                    <Toolbars>
                        <f:Toolbar ID="Toolbar4" Position="Bottom" ToolbarAlign="Right" runat="server">
                            <Items>
                                 <f:Button ID="btnDownTemplate" Hidden="true" Text="下载模板" runat="server" EnableAjax="false" DisableControlBeforePostBack="false" 
                                     EnablePostBack="true" OnClick="btnDownTemplate_Click"></f:Button>
                                <f:Button ID="btnExport" Hidden="true" Text="下载明细" runat="server" 
                                    EnableAjax="false" EnablePostBack="true" DisableControlBeforePostBack="false" OnClick="btnExport_Click"></f:Button>
                               
                            </Items>
                        </f:Toolbar>
                    </Toolbars>
                </f:SimpleForm>
            </Items>
        </f:Window>

        <br />
        <br />
        <br />
    </form>
    <script src="../res/js/ApprovalButton.js"></script>
    <script src="../res/third-party/my97/WdatePicker.js" type="text/javascript"></script>
    <script>
        var windowClientID = '<%= Window1.ClientID %>';
        var gridClientID = '<%= Grid1.ClientID %>';
        var btnSaveClientID = '<%= btnSave.ClientID %>';
        var formClientID = '<%= SimpleForm1.ClientID %>';
        var hfFormIDClientID = '<%= hfFormID.ClientID %>';
        var tbxFormTEMPLATE_NAMEClientID = '<%= tbxFormTEMPLATE_NAME.ClientID %>';
        var tbxFormTEMPLATE_DATAClientID = '<%= tbxFormTEMPLATE_DATA.ClientID %>';
        var tbxFormTEMPLATE_REMARKClientID = '<%= tbxFormTEMPLATE_REMARK.ClientID %>';
        var chlFormDEDUCT_ITEMSClientID = '<%= chlFormDEDUCT_ITEMS.ClientID %>';
        var chlFormSALARY_ITEMSClientID = '<%= chlFormSALARY_ITEMS.ClientID %>';
        var chlFormTOTAL_SALARY_ITEMSClientID = '<%= chlFormTOTAL_SALARY_ITEMS.ClientID %>';
        var chlFormTOTAL_DEDUCT_ITEMSClientID = '<%= chlFormTOTAL_DEDUCT_ITEMS.ClientID %>';


        var tbxMonthSearchClientID = '<%= tbxMonthSearch.ClientID %>';
        F.ready(function () {
            var tbxMonthSearch = F(tbxMonthSearchClientID);
            tbxMonthSearch.onTriggerClick = function () {
                WdatePicker({
                    el: tbxMonthSearchClientID + '-inputEl',
                    dateFmt: 'yyyy-MM',
                    onpicked: function () {
                        // 确认选择后，执行触发器输入框的客户端验证
                        tbxMonthSearch.validate();
                    }
                });
            };
            var tbxFormTEMPLATE_DATA = F(tbxFormTEMPLATE_DATAClientID);
            tbxFormTEMPLATE_DATA.onTriggerClick = function () {
                WdatePicker({
                    el: tbxFormTEMPLATE_DATAClientID + '-inputEl',
                    dateFmt: 'yyyy-MM',
                    onpicked: function () {
                        // 确认选择后，执行触发器输入框的客户端验证
                        tbxFormTEMPLATE_DATA.validate();
                    }
                });
            };
        });
        function onNewButtonClick(event) {
            // 重置表单字段
            F(formClientID).reset();
            F(hfFormIDClientID).setValue(null);
            // 弹出窗体
            F(windowClientID).show();
            F(windowClientID).setTitle('新增数据');
        }
        function onEditButtonClick(event) {
            showEditWindow();
        }
        function showEditWindow(rowId) {
            var grid = F(gridClientID);

            // 如果传入参数为空，则获取当前选中行
            if (!rowId) {
                var selectedRowIds = grid.getSelectedRows();
                if (!selectedRowIds.length) {
                    F.alert('请至少选择一项！');
                    return;
                }

                rowId = selectedRowIds[0];
            }
            F(windowClientID).setTitle('编辑数据');
            // 当前行数据
            var rowValue = grid.getRowValue(rowId);
            // 使用当前行数据填充表单字段
            F(hfFormIDClientID).setValue(rowId);
            F(tbxFormTEMPLATE_NAMEClientID).setValue(rowValue['TEMPLATE_NAME']);
            F(tbxFormTEMPLATE_DATAClientID).setValue(rowValue['TEMPLATE_DATA']);
            F(tbxFormTEMPLATE_REMARKClientID).setValue(rowValue['TEMPLATE_REMARK']);
            var mappingValue = rowValue['TEMPLATE_ITEM'].split(',');
            F(chlFormDEDUCT_ITEMSClientID).setValue(mappingValue);
            F(chlFormSALARY_ITEMSClientID).setValue(mappingValue);

            var mappingValue = rowValue['TEMPLATE_TOTAL'].split(',');
            F(chlFormTOTAL_SALARY_ITEMSClientID).setValue(mappingValue);
            F(chlFormTOTAL_DEDUCT_ITEMSClientID).setValue(mappingValue);
            // 弹出新增窗体
            F(windowClientID).show();
        }


        var windowUploadClientID = '<%= Window2.ClientID %>'
        var formUploadClientID = '<%= SimpleForm2.ClientID %>';
        var tbxFormUploadMessageClientID = '<%= tbxFormUploadMessage.ClientID %>';
        function onUploadExcel() {
            var grid = F(gridClientID);
            F(formUploadClientID).reset();
            var rowId;
            var selectedRowIds = grid.getSelectedRows();
            if (!selectedRowIds.length) {
                F.alert('请至少选择一项！');
                return;
            }
            rowId = selectedRowIds[0];
            var rowValue = grid.getRowValue(rowId);
            F(tbxFormUploadMessageClientID).setValue(rowValue["TEMPLATE_NAME"]);
            // 重置表单字段

            // 弹出窗体
            F(windowUploadClientID).show();
            F(windowUploadClientID).setTitle('上传表格');
        }
    </script>
</body>
</html>
